package com.javaspeak.designpatterns.go4.creational.abstractfactory;

/**
 * The ShapeSelector is responsible for returning the correct ShapeFactory.
 * The ShapeFactory can be either a SquareFactory or a TriangleFactory.
 *
 * @author John Dickerson
 */
public class ShapeSelector {

    enum ShapeType {

        SQUARE, TRIANGLE;
    }


    /**
     * Returns the appropriate ShapeFactory for the ShapeType
     *
     * @param shapeType Enum specifying Shape type
     * @return Factory that implements ShapeFactory
     */
    public static ShapeFactory getShapeFactory( ShapeType shapeType ){

        switch( shapeType ){

            case TRIANGLE:
                return new TriangleFactory();

            case SQUARE:
                return new SquareFactory();

            default:
                throw new UnsupportedOperationException( "Not supported" );
        }
    }
}
